import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

import libAssets from "@laynezh/vite-plugin-lib-assets";

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    // 库模式配置
    lib: {
      // 入口文件
      entry: "./src/index.ts",
      // ESModule模式
      formats: ["es"],
      // 输出的文件名
      fileName: "index",
    },
    rollupOptions: {
      // 外部化处理那些你不想打包进库的依赖
      external: [
        "vue",
        "vue-i18n",
        "vue-router",
        "pinia",
        "element-plus",
        "axios",
        "jmash-core",
      ],
      output: {
        // 为外部化的依赖提供一个全局变量
        globals: {
          vue: "Vue",
        },
      },
    },
  },
  plugins: [
    vue(),
    AutoImport({ resolvers: [ElementPlusResolver()] }),
    Components({}),
    libAssets()
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});
